package com.ciei.dpagm.controller;

import com.alibaba.fastjson.JSONObject;
import com.ciei.dpagm.common.controller.BaseController;
import com.ciei.dpagm.entity.Users;
import com.ciei.dpagm.service.ProjectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @author pp
 * @date 2023/05/06
 */
@Controller
@RequestMapping("project")
public class ProjectController extends BaseController {
    @Autowired
    private ProjectService projectService;

    @RequestMapping("getList")
    @ResponseBody
    public JSONObject getList(@RequestBody JSONObject data) {
        return projectService.getList(data);
    }

    @RequiresPermissions("projectManagement:projectSetting:add")
    @RequestMapping("add")
    @ResponseBody
    public JSONObject add(@RequestBody JSONObject data) {
        Users user = (Users) SecurityUtils.getSubject().getPrincipal();
        return projectService.add(data,user);
    }
    @RequestMapping("update")
    @ResponseBody
    public JSONObject update(@RequestBody JSONObject data) {
        Users user = (Users) SecurityUtils.getSubject().getPrincipal();
        return projectService.update(data,user);
    }

    @RequestMapping("init")
    @ResponseBody
    public JSONObject init(@RequestBody JSONObject data) {
        return projectService.init(data);
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONObject delete(@RequestBody JSONObject data) {
        return projectService.delete(data);
    }

    @RequestMapping("deleteBatch")
    @ResponseBody
    public JSONObject batchDelete(@RequestBody JSONObject data) {
        return projectService.batchDelete(data);
    }

    @RequestMapping("initConfig")
    @ResponseBody
    public JSONObject initConfig(@RequestBody JSONObject data) {
        return projectService.initConfig(data);
    }

    @RequiresPermissions("projectManagement:projectSetting:save")
    @RequestMapping("saveConfig")
    @ResponseBody
    public JSONObject saveConfig(@RequestBody JSONObject data) {
        Users user = (Users) SecurityUtils.getSubject().getPrincipal();
        return projectService.saveConfig(data,user);
    }

    @RequiresPermissions("projectManagement:projectSetting:export")
    @RequestMapping("exportDriverFile")
    @ResponseBody
    public JSONObject exportDriverFile(@RequestBody JSONObject data, HttpServletResponse response){
        return projectService.exportDriverFile(data,response);
    }

    @RequestMapping("dependencyRuleCheck")
    @ResponseBody
    public JSONObject dependencyRuleCheck(@RequestBody JSONObject data){
        return projectService.dependencyRuleCheck(data);
    }

    @RequestMapping("multipleDependencyRuleCheck")
    @ResponseBody
    public JSONObject multipleDependencyRuleCheck(@RequestBody JSONObject data){
        return projectService.multipleDependencyRuleCheck(data);
    }

    @RequestMapping("ruleCheck")
    @ResponseBody
    public JSONObject ruleCheck(@RequestBody JSONObject data){
        return projectService.ruleCheck(data);
    }

}
